﻿<UserControl x:Class="KlearTweet.Client.Tab.TabHeader"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Input="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input">
    <UserControl.Resources>

        <!-- Custom toggle button template -->
        <Style x:Name="ComboToggleButton" TargetType="ToggleButton">
            <Setter Property="Foreground" Value="#FF333333"/>
            <Setter Property="IsTabStop" Value="False" />
            <Setter Property="Background" Value="#FF1F3B53"/>
            <Setter Property="Padding" Value="0"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ToggleButton">
                        <Grid>
                            <Rectangle Fill="Transparent" />
                            <ContentPresenter
                            x:Name="contentPresenter"
                            Content="{TemplateBinding Content}"
                            ContentTemplate="{TemplateBinding ContentTemplate}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            Margin="{TemplateBinding Padding}"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="AutoCompleteComboBoxStyle" TargetType="Input:AutoCompleteBox">

            <!-- ComboBox should not perform text completion by default -->
            <Setter Property="IsTextCompletionEnabled" Value="False" />

            <!-- The minimum prefix length should be 0 for combo box scenarios -->
            <Setter Property="MinimumPrefixLength" Value="0" />

            <!-- Regular template values -->
            <Setter Property="Background" Value="#FF1F3B53"/>
            <Setter Property="IsTabStop" Value="False" />
            <Setter Property="HorizontalContentAlignment" Value="Left"/>
            <Setter Property="BorderBrush">
                <Setter.Value>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FFA3AEB9" Offset="0"/>
                        <GradientStop Color="#FF8399A9" Offset="0.375"/>
                        <GradientStop Color="#FF718597" Offset="0.375"/>
                        <GradientStop Color="#FF617584" Offset="1"/>
                    </LinearGradientBrush>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Input:AutoCompleteBox">
                        <Grid Margin="{TemplateBinding Padding}">
                            <TextBox IsTabStop="True" x:Name="Text" Style="{TemplateBinding TextBoxStyle}" Margin="0" />
                            <ToggleButton 
                                HorizontalAlignment="Right"
                                VerticalAlignment="Center"
                                Style="{StaticResource ComboToggleButton}"
                                Margin="0"
                                HorizontalContentAlignment="Center" 
                                Background="{TemplateBinding Background}" 
                                BorderThickness="0" 
                                Height="16" Width="16"
                                Click="DropDownToggle_Click">
                                <ToggleButton.Content>
                                    <Path x:Name="BtnArrow" Height="4" Width="8" Stretch="Uniform" Data="F1 M 301.14,-189.041L 311.57,-189.041L 306.355,-182.942L 301.14,-189.041 Z " 
                                          Margin="0,0,6,0" HorizontalAlignment="Right">
                                        <Path.Fill>
                                            <SolidColorBrush x:Name="BtnArrowColor" Color="#FF333333"/>
                                        </Path.Fill>
                                    </Path>
                                </ToggleButton.Content>
                            </ToggleButton>
                            <Popup x:Name="Popup">
                                <Border x:Name="PopupBorder" HorizontalAlignment="Stretch" Opacity="1.0" BorderThickness="0" CornerRadius="3">
                                    <Border.RenderTransform>
                                        <TranslateTransform X="2" Y="2" />
                                    </Border.RenderTransform>
                                    <Border.Background>
                                        <SolidColorBrush Color="#11000000" />
                                    </Border.Background>
                                    <Border HorizontalAlignment="Stretch" BorderThickness="0" CornerRadius="3">
                                        <Border.Background>
                                            <SolidColorBrush Color="#11000000" />
                                        </Border.Background>
                                        <Border.RenderTransform>
                                            <TransformGroup>
                                                <ScaleTransform />
                                                <SkewTransform />
                                                <RotateTransform />
                                                <TranslateTransform X="-1" Y="-1" />
                                            </TransformGroup>
                                        </Border.RenderTransform>
                                        <Border HorizontalAlignment="Stretch" Opacity="1.0" Padding="2" BorderThickness="2" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="3">
                                            <Border.RenderTransform>
                                                <TransformGroup>
                                                    <ScaleTransform />
                                                    <SkewTransform />
                                                    <RotateTransform />
                                                    <TranslateTransform X="-2" Y="-2" />
                                                </TransformGroup>
                                            </Border.RenderTransform>
                                            <Border.Background>
                                                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                                    <GradientStop Color="#FFDDDDDD" Offset="0"/>
                                                    <GradientStop Color="#AADDDDDD" Offset="1"/>
                                                </LinearGradientBrush>
                                            </Border.Background>
                                            <ListBox x:Name="Selector" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemTemplate="{TemplateBinding ItemTemplate}" />
                                        </Border>
                                    </Border>
                                </Border>
                            </Popup>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <DataTemplate x:Key="SearchItemTemplate">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="16" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <ContentPresenter Content="{Binding Icon}" />
                <TextBlock Foreground="{Binding ForegroundColor}" Padding="6, 0, 0, 0" Text="{Binding DisplayText}" Grid.Column="1" />
            </Grid>
        </DataTemplate>

        <LinearGradientBrush x:Name="SearchingBrush" EndPoint="0.498,0.328" StartPoint="0.498,-0.672">
            <GradientStop Color="#FF3B3B3B"/>
            <GradientStop Color="#FF11CC00" Offset="1"/>
        </LinearGradientBrush>
        <LinearGradientBrush x:Name="FailedBrush" EndPoint="0.498,0.328" StartPoint="0.498,-0.672">
            <GradientStop Color="#FF3B3B3B"/>
            <GradientStop Color="#FFCC1100" Offset="1"/>
        </LinearGradientBrush>
        <LinearGradientBrush x:Name="DefaultBrush" EndPoint="0.498,0.328" StartPoint="0.498,-0.672">
            <GradientStop Color="#FF3B3B3B"/>
            <GradientStop Color="#FFB1BBD5" Offset="1"/>
        </LinearGradientBrush>

    </UserControl.Resources>

    <Border Margin="2" Padding="2" BorderBrush="DarkGray" BorderThickness="1" CornerRadius="2">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <ProgressBar x:Name="ProgressBar" Grid.ColumnSpan="2" />

            <Input:AutoCompleteBox Grid.Column="0" x:Name="OmniBox" MinWidth="50" MaxWidth="400"
                ItemTemplate="{StaticResource SearchItemTemplate}"
                Style="{StaticResource AutoCompleteComboBoxStyle}"
                MinimumPopulateDelay="200" />

            <ToggleButton Grid.Column="1" x:Name="ToggleActions" Content="A" Margin="10,0" />
        </Grid>
    </Border>
</UserControl>
